package com.holly.controller;

import com.holly.pojo.Emp;
import com.holly.pojo.EmpQueryParam;
import com.holly.pojo.PageResultData;
import com.holly.pojo.Result;
import com.holly.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author holly
 * @create 2025-06-29 16:55
 */
@RequestMapping("/emps")
@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam  param){
        log.info("分页查询，参数：param{}",param);
        PageResultData<Emp> pageResultData = empService.page(param);
        return Result.success(pageResultData);
    }

    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("保存员工，参数：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工，参数：{}",ids);
        empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id){
        log.info("根据员工id查询员工信息，参数：{}",id);
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("更新员工信息，参数：{}",emp);
        empService.update(emp);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list(){
        log.info("查询所有员工信息");
        List<Emp> list = empService.list();
        return Result.success(list);
    }


}
